﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetfractionHub.Network.Protocol.BASE.Factory
{
    public class FactorySCH : ProtocolMessageFactory
    {
        public enum ParameterEnum : int
        {
            SessionId = 1,
            Include = 2,
            Exclude = 3,
            Extension = 4,
            LessThanSize = 5,
            GreaterThanSize = 6,
            EqualToSize = 7,
            Token = 8,
            Type = 9
        }

        public override ProtocolMessage Create(ProtocolMessage.MessageTypeEnum messageType, Dictionary<int, object> parameters)
        {
            ProtocolMessage proto = new ProtocolMessage(messageType, ProtocolFeatureBASE.FeatureActions.ActionSCH);

            foreach (ParameterEnum en in parameters.Keys)
            {
                proto.Parameters.Add(new ProtocolParameter(GetParameterCodeForParameter((ParameterEnum)en), parameters[(int)en].ToString()));
            }
            
            return proto;
        }

        private string GetParameterCodeForParameter(ParameterEnum param)
        {
            switch (param)
            {
                case ParameterEnum.Include:
                    return "AN";
                case ParameterEnum.Exclude:
                    return "NO";
                case ParameterEnum.Extension:
                    return "EX";
                case ParameterEnum.LessThanSize:
                    return "LE";
                case ParameterEnum.GreaterThanSize:
                    return "GE";
                case ParameterEnum.EqualToSize:
                    return "EQ";
                case ParameterEnum.Token:
                    return "TO";
                case ParameterEnum.Type:
                    return "TY";
                default:
                    return "";
            }
        }
    }
}
